using System.Linq;
using Magiq.Delete;
using Magiq.Support;

namespace Magiq.Providers.Objects
{
    public class DeleteStrategy<T> :  IDeleteStrategy where T : class
    {
        private readonly IDelete<T> delete;

        public DeleteStrategy(IDelete<T> delete) 
        {
            this.delete = delete;
        }

        #region IDeleteStrategy Members

        public int Execute()
        {
            var list = new EnumerableSource(delete.Source).List;
            var count = 0;
            foreach (var item in delete.Source.ToArray())
            {
                list.Remove(item);
                count++;
            }
            return count;
        }

        #endregion
    }
}